package com.vcc.service.impl;

import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.vcc.data.entity.ClientRolePermission;
import com.vcc.data.mapper.ClientRolePermissionMapper;
import com.vcc.service.service.ClientRolePermissionService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClientRolePermissionServiceImpl extends ServiceImpl<ClientRolePermissionMapper, ClientRolePermission> implements ClientRolePermissionService {
    @Override
    public Boolean existsByRoleIdAndPermissionId(Long roleId, Long permissionId) {
        return queryChain()
                .eq(ClientRolePermission::getRoleId, roleId)
                .eq(ClientRolePermission::getPermissionId, permissionId)
                .exists();
    }

    @Override
    public boolean deleteByRoleId(Long roleId) {
        return remove(queryChain().eq(ClientRolePermission::getRoleId, roleId));
    }

    @Override
    public boolean deleteByPermissionId(Long permissionId) {
        return remove(queryChain().eq(ClientRolePermission::getPermissionId, permissionId));
    }

    @Override
    public Boolean deleteByRoleIdsAndPermissionId(Long permissionId, List<Long> roleIds) {
        return remove(queryChain()
                .eq(ClientRolePermission::getPermissionId, permissionId)
                .in(ClientRolePermission::getRoleId, roleIds));
    }
}
